package com.ysd.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ysd.entity.Read_room;
import com.ysd.repository.Read_roomRepository;
import com.ysd.util.Result;

@RestController
public class Read_roomController {
	@Autowired
	private Read_roomRepository rrm;
	//查全部
	@RequestMapping("Read_rm")
	public Object Read_rm(Read_room r) {
		List<Read_room> list=rrm.findAll();
		if (list!=null) {
			return Result.toClient("0", "成功", null, list);
		} else {
			return Result.toClient("1", "失败", null, list);
		}
	}
	//删除
	@RequestMapping("Read_oo")
	public Object Read_oo(int id) {
//		Cannot return a void result
//		不能返回一个无返回值
		try {
			rrm.delete(id);
			return Result.toClient("0", "成功", null, null);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return Result.toClient("1", "失败", null, null);
		}
		
	}
	//添加
	@RequestMapping("Read_ro")
	public Object Read_ro(String ziYuanName) {
		int i=rrm.insertRead(ziYuanName);
		Map<String, Object>map=new HashMap<String, Object>();
		if(i>0) {
			return Result.toClient("0", "成功", null, null);
		}else {
			return Result.toClient("1", "失败", null, null);
		}
	}
	//修改
	@RequestMapping("Read_ra")
	public Object Read_ra(String ziYuanName,int id) {
		int i=rrm.updateRead(ziYuanName,id);
		Map<String, Object>map=new HashMap<String, Object>();
		if(i>0) {
			return Result.toClient("0", "成功", null, null);
		}else {
			return Result.toClient("1", "失败", null, null);
		}
	}
	
	
	
}
